from base.device import DeviceBasic
from packages import AppPackages
from utils.command import XHS


class Xhs(DeviceBasic):
    def __init__(self, device):
        super().__init__(device, packages_name=AppPackages.xhs.packages_name)

    def user(self, user_id):
        ...

    def note(self, note_id, retry=5):
        while retry > 0:
            retry -= 1
            out, code = self._device.shell(XHS.note.format(note_id))
            if code != 0:
                return False
            # 检查有没有点赞收藏评论view
            if self._device(resourceId="com.xingin.xhs:id/ahs"):
                return True
            # 检查验证码
        return False

    def swipe_down(self):
        return self._device.shell('input touchscreen swipe 537 1664 531 337 100')

    def get_is_end(self):
        """
        判断是否到底部
        :return:
        """
        element = self._device(text="- THE END -")
        blank_data_element = self._device(resourceId="com.xingin.xhs:id/avw")
        if blank_data_element.exists():
            return True
        if element.exists():
            return True
